Skip to content

West Midlands | 25-SDC-July | Gabriel Deng | Sprint 2 | Improve with caches#71

Open
gai93003 wants to merge 1 commit intoCodeYourFuture:mainfrom
gai93003:improve_with_caches
Open

West Midlands | 25-SDC-July | Gabriel Deng | Sprint 2 | Improve with caches#71
gai93003 wants to merge 1 commit intoCodeYourFuture:mainfrom
gai93003:improve_with_caches

Conversation

@gai93003
Copy link

No description provided.

@gai93003 gai93003 added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Jan 13, 2026
Comment on lines 20 to 38
@@ -29,4 +36,6 @@ def ways_to_make_change_helper(total: int, coins: List[int]) -> int:
intermediate = ways_to_make_change_helper(total - total_from_coins, coins=coins[coin_index+1:])
ways += intermediate
count_of_coin += 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From line 36, we can figure out coins can only be one of the following 9 lists:

[200, 100, 50, 20, 10, 5, 2, 1]
[100, 50, 20, 10, 5, 2, 1]
[50, 20, 10, 5, 2, 1]
...
[1]
[]

We could further improve the performance if we can

  • avoid repeatedly creating the same sub-lists at line 36, and
  • create key as (total, a_value_identifiying_one_of_the_sublists) instead of as (total, tuple(coins))

I don't think this exercise expects trainees to optimize the code to this level. So change is optional.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants